﻿#region The Apache Software License

/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  ported to C# by Artur Trosin
 */

#endregion

// From here: http://ndddsample.googlecode.com/svn/trunk/src/NDDDSample/app/infrastructure/NDDDSample.Infrastructure/Builders/BitConverterUtil.cs

namespace CatchUpTv.Utilities
{
    #region Usings

    using System;

    #endregion

    /// <summary>
    /// Utility methods for bit conversion.
    /// </summary>
    public static class BitConverterUtil
    {
        /// <summary>
        /// Returns a representation of the specified floating-point value in
        /// IEEE 754 floating-point single format bit layout. 
        /// </summary>
        /// <param name="value">the floating point number convert</param>
        /// <returns>A 32-bit signed integer whose bits represent the floating point 
        /// number</returns>
        /// <remarks>
        /// If the argument is positive infinity, the result is 0x7f800000.
        /// If the argument is negative infinity, the result is 0xff800000.
        /// If the argument is NaN, the result is 0xffc00000.
        /// </remarks>
        public static int SingleToInt32Bits(float value)
        {
            return BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
        }
    }
}